package com.laoniu.service.sys;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.laoniu.mapper.SysMenuMapper;
import com.laoniu.entity.SysMenu;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysMenuService extends ServiceImpl<SysMenuMapper, SysMenu> {

    @Resource
    private SysMenuMapper menuMapper;

    /**
     * 根据父id查询菜单
     * @param parentId
     * @return
     */
    public List<SysMenu> selectByParentId(Long parentId) {
        LambdaQueryWrapper<SysMenu> wrapper = Wrappers.lambdaQuery(SysMenu.class);
        wrapper.eq(SysMenu::getParentId, parentId);
        wrapper.orderByAsc(SysMenu::getOrderNum);
        return menuMapper.selectList(wrapper);
    }

    public List<SysMenu> selectList() {
        LambdaQueryWrapper<SysMenu> wrapper = Wrappers.lambdaQuery(SysMenu.class);
        wrapper.orderByAsc(SysMenu::getOrderNum);
        return menuMapper.selectList(wrapper);
    }

    public List<SysMenu> selectMenuByUserId(Long userId) {
        return menuMapper.selectMenuByUserId(userId);
    }

    public List<SysMenu> listAll() {
        LambdaQueryWrapper<SysMenu> wrapper = Wrappers.lambdaQuery(SysMenu.class);
        wrapper.eq(SysMenu::isView, true);
        wrapper.orderByAsc(SysMenu::getOrderNum);
        return menuMapper.selectList(wrapper);
    }
}
